package com.example.jhf;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;

/**
 * 首页
 * 
 * @author JiangJie
 *
 */
public class IndexActivity extends FragmentActivity implements OnCheckedChangeListener{
	private Context context;
	private RadioButton ra_home;
	private RadioButton ra_class;
	private RadioButton ra_shcool;
	private RadioButton ra_person;
	private OneFragment oneFragment = new OneFragment();
	private TwoFragment twoFragment = new TwoFragment();
	private ThreeFragment threeFragment = new ThreeFragment();
	private FourFragment fourFragment = new FourFragment();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.bottom_menu);
		init();
		
	}
	@Override
	protected void onStart() {
		super.onStart();		
	}

	private void init() {
		context = this;
		ra_home =(RadioButton) findViewById(R.id.homepage);
		ra_home.setOnCheckedChangeListener(this);
		ra_class = (RadioButton) findViewById(R.id.bjkj);
		ra_class.setOnCheckedChangeListener(this);
		ra_shcool = (RadioButton) findViewById(R.id.xydt);
		ra_shcool.setOnCheckedChangeListener(this);
		ra_person = (RadioButton) findViewById(R.id.grzx);
		ra_person.setOnCheckedChangeListener(this);		
		setDefaultFragment();
	}
	
	private void setDefaultFragment(){//默认的界面   1
		FragmentManager manager = getSupportFragmentManager();	
		FragmentTransaction transaction = manager.beginTransaction();
		transaction.add(R.id.fragmentRoot, oneFragment, "home");
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);  
		transaction.commit();
	}
	

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			FragmentManager manager = getSupportFragmentManager();	
			FragmentTransaction transaction = manager.beginTransaction();
			switch (buttonView.getId()) {
			case R.id.homepage:
				ra_class.setChecked(false);
				ra_shcool.setChecked(false);
				ra_person.setChecked(false);
				transaction.replace(R.id.fragmentRoot, oneFragment,"home");
				transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);  
				break;
			case R.id.bjkj:		
				ra_home.setChecked(false);
				ra_shcool.setChecked(false);
				ra_person.setChecked(false);
				transaction.replace(R.id.fragmentRoot, twoFragment,"simulation");
				transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);  
				break;
			case R.id.xydt:				
				ra_home.setChecked(false);
				ra_class.setChecked(false);
				ra_person.setChecked(false);
				transaction.replace(R.id.fragmentRoot, threeFragment,"user");
				transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);  
				break;
			case R.id.grzx:	
				ra_home.setChecked(false);
				ra_shcool.setChecked(false);
				ra_class.setChecked(false);
				transaction.replace(R.id.fragmentRoot, fourFragment,"user");
				transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);  
				break;				
			}			
			transaction.commit();
		}
	}
	
}
